package model.utils;

import com.example.towerdefence.R;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;

/**
 * Class implementing singleton pattern. It is container for the sounds of the
 * game.
 * 
 * @author EvilTeam
 * 
 */
public class Sounds {

	private static SoundPool sounds = new SoundPool(10,
			AudioManager.STREAM_MUSIC, 0);
	private static int blast;
	private static MediaPlayer menuMusic;
	private static Sounds sound = null;

	/**
	 * Set's an instance for the sound.
	 * 
	 * @param context
	 *            - needed to get recourses from the activity
	 */
	public static void setInstanceOfSounds(Context context) {
		if (sound == null)
			sound = new Sounds(context);
	}

	/**
	 * 
	 * @return sound instance.
	 */
	public static Sounds getInstanceOfSounds() {
		return sound;
	}

	private Sounds(Context context) {
		blast = sounds.load(context, R.raw.blast_sound, 1);
		menuMusic = MediaPlayer.create(context, R.raw.backinblackmenu);
	}

	/**
	 * Playing a sound when a tower is shooting.
	 */
	public static void playSoundOnShoot() {
		sounds.play(blast, 1.0f, 1.0f, 0, 0, 1.5f);
	}

	/**
	 * Playing a sound when the game is started(in the main menu).
	 */
	public static void playSoundOnMenu() {
		menuMusic.start();
	}
	/**
	 * Pauses the game menus sounds.
	 */
	public static void pauseSoundOnMenu() {
		menuMusic.pause();
	}

	/**
	 * Stops the game menu sounds.
	 */
	public static void stopSoundOnMenu() {
		menuMusic.stop();
	}

}
